from django.contrib import admin
from pyplog.photos.models import Contribution, Gallery, Photo
from pyplog.photos.views import key_classes

class GenericPhotoAttributeAdmin(admin.ModelAdmin):
	prepopulated_fields = { "slug" : ("title",) }
	
for key in key_classes:
	if key == "artist":
		# artist admin is defined in pyplog.artists.admin
		continue
	admin.site.register(key_classes[key], GenericPhotoAttributeAdmin)

class GalleryAdmin(GenericPhotoAttributeAdmin):
	fieldsets = (
		(None, {
			"fields" : ("title", "slug")
		}),
		("Advanced settings", {
			"classes" : ("collapse",),
			"fields" : ("position", "password")
		}),
	)
admin.site.unregister(Gallery)
admin.site.register(Gallery, GalleryAdmin)

class ContribInline(admin.StackedInline):
	model = Contribution
	extra = 2

class PhotoAdmin(admin.ModelAdmin):
	date_hierarchy = "published"
	fieldsets = (
		(None, {
			"fields" : ("title", "slug", "published", "description")
		}),
		("Image data", {
			"fields" : ("source_image",)
		}),
		("References", {
			"fields" : ("gallery", "license", "location", "tags")
		}),
	)
	inlines = (ContribInline,)
	list_display = ("title", "gallery", "published")
	list_filter = ("gallery",)
	prepopulated_fields = { "slug" : ("title",) }
admin.site.register(Photo, PhotoAdmin)